package ch.unisi.inf.editor;

import java.awt.Color;
import ch.unisi.inf.engine.Image;
/**
 * redraws the image swapping the pixel at position x with the pixel at width - x - 1 
 * 
 * @author  matthias.eberli@lu.unisi.ch
 */
public class MirrorFilter extends Filter
{
    private Image tempImage;
    public MirrorFilter(final String name)
    {
        super(name);
    }
    
    public void apply(final Image image)
    {
        tempImage = new Image(image.getPath(), image);
        final int height = image.getHeight();
        final int width = image.getWidth();
        for(int y = 0; y < height; y++) {
            for(int x = 0; x < width; x++) {
                Color pixel = tempImage.getPixel(x,y);
                image.setPixel(width-x-1, y, new Color(pixel.getRed(), pixel.getGreen(), pixel.getBlue()));
            }
        }
    }   
}
